﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;

namespace filesync
{
    class Program
    {
        static void Main(string[] args)
        {
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                    .AddFilter("Microsoft", LogLevel.Warning)
                    .AddFilter("System", LogLevel.Warning)
                    .AddFilter("LoggingConsoleApp.Program", LogLevel.Debug)
                    .AddConsole()
                    .AddEventLog();
            });
            var logger = loggerFactory.CreateLogger<FileSync>();

            var builder = new ConfigurationBuilder()
               .AddCommandLine(args);

            var configuration = builder.Build();

            if (string.IsNullOrWhiteSpace(configuration["path"]))
            {
                Console.WriteLine("请输入需要同步的文件夹");
                return;
            }

            var fileSync = new FileSync(new FileSyncOptions { Path = configuration["path"] }, logger);


            AppDomain.CurrentDomain.ProcessExit += (s, e) =>
            {
                Console.WriteLine($"{DateTime.Now} 后台测试服务，准备进行资源清理！");
                fileSync.Stop();
                Environment.Exit(0);
            };

            fileSync.Start();
        }
    }
}
